home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 967 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.5 KB  |  73 lines

  1. Path: cs.mu.OZ.AU!bounce-back
  2. From: Alan Griffiths <aGriffiths@ma.ccngroup.com>
  3. Newsgroups: comp.std.c++
  4. Subject: Must exception classes have copy constructors?
  5. Date: 05 Apr 96 02:58:28 GMT
  6. Organization: CCN Market Analysis
  7. Approved: fjh@cs.mu.oz.au
  8. Message-ID: <606373375wnr@ma.ccngroup.com>
  9. Reply-To: aGriffiths@ma.ccngroup.com
  10. NNTP-Posting-Host: munta.cs.mu.oz.au
  11. X-Original-Date: Thu, 04 Apr 1996 13:52:42 GMT
  12. Return-Path: <daemon@meeker.UCAR.EDU>
  13. X-Newsreader: Newswin Alpha 0.6
  14. X-Mail2News-Path: devmaccn.demon.co.uk
  15. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  16.     iQBFAgUBMWSMquEDnX0m9pzZAQHhGgF+LPJN+5MlYFe6AAaqymAI3nFBi9oPP7DY
  17.     VGOqNRoIyleuLjC3im1ZJqU+eHIINlGp
  18.     =Bqon
  19. Originator: fjh@munta.cs.mu.OZ.AU
  20.  
  21. I've just tried porting some code to MSVC4 (it compiles and works with 
  22. SC7.1 and BC4.5).
  23.  
  24. In effect it appears that the Microsoft compiler _requires_ anything 
  25. thrown as an exception to have an accessible copy constructor.  (I've 
  26. tended to make copy constructors private to ensure catch-by-reference
  27. and aviod slicing bugs.)
  28.  
  29. Looking through the DWP I can't see any reason to require a copy 
  30. constructor, but there are references to copying temporaries.
  31.  
  32. Is MSVC4 correct?
  33.  
  34. code:
  35. class MyBaseException {
  36. public:  MyBaseException() {}
  37.          virtual char* what() = 0;
  38. private: MyBaseException(const MyBaseException&);
  39. };
  40.  
  41. class MyException1 : public  MyBaseException {
  42. public:     virtual char* what() { return "MyException1"; }
  43. };
  44.  
  45. int main() {
  46.     try     {
  47.         throw MyException1();
  48. // error C2700: 'class MyException1' : cannot be thrown (use -W4 for more info)
  49.  
  50. // warning C4671: 'MyException1' : the copy constructor is inaccessible
  51.     } catch (MyBaseException& e) {
  52.         cout << "OK - got here (" << __LINE__ << ") : have a " << e.what()
  53.         << endl;
  54.     } catch (...) {
  55.         cout << "ERROR - got here (" << __LINE__ << ")" << endl;
  56.     }
  57.     return 0;
  58. }
  59.  
  60.  
  61. --
  62. Alan Griffiths               | Also editor of: The ISDF Newsletter
  63. Senior Systems Consultant,   | (An Association of C and C++ Users publication)
  64. CCN Group Limited.           | (ISDF editor  : isdf@octopull.demon.co.uk)
  65. (agriffiths@ma.ccngroup.com) | (For ACCU see : http://bach.cis.temple.edu/accu)
  66.  
  67. ---
  68. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  69. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  70. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  71. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  72. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  73.